home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ColorExtension / Sources / CEServer.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  5.3 KB  |  194 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                CEServer.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef CESERVER_H
  11. #include "CEServer.h"
  12. #endif
  13.  
  14. #ifndef CEPRVGLU_H
  15. #include "CEPrvGlu.h"
  16. #endif
  17.  
  18. #ifndef FWEXTMGR_H
  19. #include "FWExtMgr.h"
  20. #endif
  21.  
  22. #ifndef FWPART_H
  23. #include "FWPart.h"
  24. #endif
  25.  
  26. #ifndef CECLIENT_H
  27. #include "CEClient.h"
  28. #endif
  29.  
  30. #ifndef __CODEFRAGMENTS__
  31. #include <CodeFragments.h>
  32. #endif
  33.  
  34. //========================================================================================
  35. // Static Function Prototypes
  36. //========================================================================================
  37.  
  38. static ODExtension* CE_CreateExtension(Environment* ev, FW_CPart* part, const char* name, void* refCon);
  39.  
  40. FW_EXTERN_C_BEGIN
  41.  
  42. static void CE_ForeColorProcGlue(Environment* ev, void* refCon, short red, short green, short blue);
  43. static void CE_BackColorProcGlue(Environment* ev, void* refCon, short red, short green, short blue);
  44.  
  45. FW_EXTERN_C_END
  46.  
  47. //========================================================================================
  48. // Static Allocations
  49. //========================================================================================
  50.  
  51. static CE_SColorExtensionProcGlue gCallbackGlue = {CE_ForeColorProcGlue, CE_BackColorProcGlue};
  52.  
  53. static ColorProc gForeColorProc;
  54. static ColorProc gBackColorProc;
  55.  
  56. //========================================================================================
  57. // Public Functions
  58. //========================================================================================
  59.  
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // CE_ExtensionLibraryExists
  63. //----------------------------------------------------------------------------------------
  64.  
  65. FW_Boolean CE_ExtensionLibraryExists()
  66. {
  67.     return (&CE_OColorExtensionClassData != (void*)kUnresolvedCFragSymbolAddress);
  68. }
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // CE_SetCallbacks
  72. //----------------------------------------------------------------------------------------
  73.  
  74. void CE_SetCallbacks(ColorProc foreColorProc, ColorProc backColorProc)
  75. {
  76.     gForeColorProc = foreColorProc;
  77.     gBackColorProc = backColorProc;
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. // CE_RegisterExtension
  82. //----------------------------------------------------------------------------------------
  83.  
  84. void CE_RegisterExtension(Environment* ev, FW_CPart* part, void* refCon)
  85. {
  86.     if (CE_ExtensionLibraryExists())
  87.     {
  88.         FW_CExtensionManager* extMgr = part->GetExtensionManager(ev);
  89.         FW_ASSERT(extMgr);
  90.         
  91.         extMgr->RegisterExtension(ev, CE_kColorExtensionName, CE_CreateExtension, refCon, TRUE);
  92.     }
  93. }
  94.  
  95. //========================================================================================
  96. // Extension Creation Callback
  97. //========================================================================================
  98.  
  99. //----------------------------------------------------------------------------------------
  100. // CE_CreateExtension
  101. //----------------------------------------------------------------------------------------
  102.  
  103. ODExtension* CE_CreateExtension(Environment* ev, 
  104.                                 FW_CPart* part, 
  105.                                 const char* name, 
  106.                                 void* refCon)
  107. {
  108. FW_UNUSED(name);
  109.     CE_OColorExtension* ce = new CE_OColorExtension;
  110.     ce->InitColorExtension(ev, part->GetODPart(ev), refCon, &gCallbackGlue);
  111.     
  112.     return ce;
  113. }
  114.  
  115. //========================================================================================
  116. // Callback Glue
  117. //========================================================================================
  118.  
  119. //----------------------------------------------------------------------------------------
  120. // CE_ForeColorProcGlue
  121. //----------------------------------------------------------------------------------------
  122.  
  123. void CE_ForeColorProcGlue(Environment* ev, 
  124.                         void* refCon, 
  125.                         short red, 
  126.                         short green, 
  127.                         short blue)
  128. {
  129.  
  130.     if (gForeColorProc)
  131.     {
  132.         FW_PlatformError error = FW_xNoError;
  133.  
  134.         FW_TRY
  135.         {
  136.             (gForeColorProc)(ev, refCon, red, green, blue);
  137.         }
  138.         FW_CATCH_BEGIN
  139.         FW_CATCH_REFERENCE(FW_XException, exception)
  140.         {
  141.             error = exception.GetPlatformError();
  142.         }
  143. #ifdef FW_DEBUG
  144.         FW_CATCH_EVERYTHING()
  145.         {
  146.             FW_DEBUG_MESSAGE("Invalid exception caught in CE_ForeColorProcGlue");
  147.             error = kODErrUndefined;
  148.         }
  149. #endif
  150.         FW_CATCH_END
  151.         
  152.         if (error != FW_xNoError)
  153.             FW_SetEvError(ev, error);
  154.     }
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. // CE_BackColorProcGlue
  159. //----------------------------------------------------------------------------------------
  160.  
  161. void CE_BackColorProcGlue(Environment* ev, 
  162.                         void* refCon, 
  163.                         short red, 
  164.                         short green, 
  165.                         short blue)
  166. {
  167.     if (gBackColorProc)
  168.     {
  169.         FW_PlatformError error = FW_xNoError;
  170.  
  171.         FW_TRY
  172.         {
  173.             (gBackColorProc)(ev, refCon, red, green, blue);
  174.         }
  175.         FW_CATCH_BEGIN
  176.         FW_CATCH_REFERENCE(FW_XException, exception)
  177.         {
  178.             error = exception.GetPlatformError();
  179.         }
  180. #ifdef FW_DEBUG
  181.         FW_CATCH_EVERYTHING()
  182.         {
  183.             FW_DEBUG_MESSAGE("Invalid exception caught in CE_ForeColorProcGlue");
  184.             error = kODErrUndefined;
  185.         }
  186. #endif
  187.         FW_CATCH_END
  188.         
  189.         if (error != FW_xNoError)
  190.             FW_SetEvError(ev, error);
  191.     }
  192. }
  193.  
  194.